#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;


int main(int argc, char **argv)
{
    map<int, int> myMap;
    //int arr[] = {1, 1, 1, 1, 1, 1, 1, 1};
    int arr[] = {0, 0, 1, 1, 0};
    int cur = 0, maxDis = -1;;
    myMap[0] = -1;
    for (int i = 0; i < sizeof(arr)/sizeof(int); i++) {
	if (arr[i] == 1) cur += 1;
	else cur -= 1;
	if (myMap.count(cur) == 0) myMap[cur] = i;
	else {
	    int dis = i - myMap[cur] ;
	    if (dis > maxDis) maxDis = dis;
	}
    }
    cout << "Max dis is: " << maxDis << endl;
}
